<%@ page language="java" import="org.json.*,java.sql.*,com.microsoft.sqlserver.jdbc.*,java.io.*,web.rec.*" 
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<% 
	Connection conn = ResourceTool.getConnection();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

			<table>
				<tr>
					<th>Student id</th>
					<th>First name</th>
					<th>Mid name</th>
					<th>Last name</th>
					<th>ssn</th>
					<th>residence</th>
					<th>units</th>
					<th>grade option</th>
				</tr>
			          <%
			try {
			// Create the prepared statement and use it to
			// INSERT the student attrs INTO the Student table.
			Statement stmt = conn.createStatement();
			String action = request.getParameter("action");
			String class_id = request.getParameter("class_id");
			if (action != null && action.equals("submit"))
			{
				String sql = "select * from student, Section, StudentTakingSection where "
						   + "student.student_id = StudentTakingSection.student_id and "
						   + "Section.section_id = StudentTakingSection.section_id and "
						   + "section.class_id = '"+ class_id + "'";
				System.out.println(sql);
				ResultSet rs = stmt.executeQuery(sql);
				while(rs.next())
				{
			%>
			<tr>
				<td><%= rs.getString("student_id") %></td>
				<td><%= rs.getString("first_name") %></td>
				<td><%= rs.getString("mid_name") %></td>
				<td><%= rs.getString("last_name") %></td>
				<td><%= rs.getString("ssn") %></td>
				<td><%= rs.getString("residence") %></td>
				<td><%= rs.getInt("units") %></td>
				<td><%= rs.getString("grade_option") %></td>
			</tr>
			<%
				}
			}
			} catch (SQLException sqle) {
				out.println(sqle.getMessage());
			} catch (Exception e) {
				out.println(e.getMessage());
			}    
			%>
	  </table>
</body>
</html>